package withdi;

import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.ClassPathResource;

public class TestDI {

    public static void main(String[] args) {

        //初始化spring环境
        //占内存，耗资源，容易导致系统运行缓慢甚至宕机
        AbstractApplicationContext context=new ClassPathXmlApplicationContext("beans.xml");
       // BeanFactory beanFactory=new XmlBeanFactory(new ClassPathResource("beans.xml"));
        //上面代码执行，那么所有bean都被容器实例化了，下面我们问容器拿

      //  UserService userService=(UserService)beanFactory.getBean("userService");

       // System.out.println(userService.isExists(13));

        UserDao userDao=(UserDao)context.getBean("userDao");

        System.out.println(userDao.selectUsername(13));
/*Bean的生命周期
实例化dao
bean的初始化方法。。。。。。。。。
实例化service
name13
bean的销毁方法。
*/


          context.close();

    }


}
